<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>物业管理系统</title>
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/AdminLTE.min.css">
</head>
<style>
</style>
<body style="padding-bottom: 90px; background-color: #ECF0F5;">
	<div class="modal-content">
		<div class="modal-body">
			<div class="form-group">
				<label class="control-label">区域：<!-- <span style="color:#F00">*</span> --></label> 
		        <select id="r_id" class="form-control">
					
				</select>
			</div>
			<div class="form-group">
				<label class="control-label">起始停车位编号：</label> <input type="text" class="form-control" id="startNumber" placeholder="示例 001,010,101">
			</div>
			<div class="form-group">
				<label class="control-label">结束停车位编号：</label> <input type="text" class="form-control" id="endNumber" placeholder="示例 001,010,101">
			</div>
			<div class="form-group">
				<label class="control-label">出售价格(元)：</label> <input type="text" class="form-control" id="sellPrice">
			</div>
			<div class="form-group">
				<label class="control-label">使用时限(年)：</label> <input type="text" class="form-control" id="timeLimit" placeholder="示例 001,010,101">
			</div>
		</div>
	</div>
</body>
<script src="${pageContext.request.contextPath}/plugins/jQuery/jquery-2.2.3.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/js/date.js"></script>
<!-- layer -->
<script src="${pageContext.request.contextPath}/plugins/layer/2.4/layer.js"></script>
<script>
	var lock = false;
	var index = parent.layer.getFrameIndex(window.name);
	var pattern = /^[0-9]*$/;//数字zhengze
	$(function() {
		$.ajax({
			url : "${pageContext.request.contextPath}/selectParkingRegionByPage",
			type : "post",
			dataType : "json",
			data : {
				offset : 0,
				limit : 999,
				name : ''
			},
			success : function(data) {
				var parkingRegion = data['rows'];
				var html="<option value=''>请选择...</option>";
				for (var i = 0; i < parkingRegion.length; i++) {
					html += "<option value='"+parkingRegion[i].id+"'>" + parkingRegion[i].regionName + "</option>";
				}
				$("#r_id").html(html);
			}
		});
	});
	
	//添加
	function insertData() {
		lock = true;
		var rId = $("#r_id").val();
		var startNumber = $("#startNumber").val();
		var endNumber = $("#endNumber").val();
		var sellPrice=$("#sellPrice").val();
		var timeLimit=$("#timeLimit").val();
		if (startNumber === '' || endNumber === '' || rId==='') {
			layer.alert("数据填写不完整!");
			lock = false;
			return;
		}
		if(!pattern.test(startNumber) || !pattern.test(endNumber)|| !pattern.test(sellPrice)|| !pattern.test(timeLimit)){
			layer.alert("编号、价格、时限填写整数!");
			lock = false;
			return;
		}
		$.ajax({
			url : "${pageContext.request.contextPath}/insertParkingSpaceList",
			type : "post",
			data : {
				rId : rId,
				startNumber : startNumber,
				endNumber : endNumber,
				sellPrice:sellPrice,
				timeLimit:timeLimit
			},
			dataType : "json",
			success : function(data) {
				var result = data['result'];
				if (result == 1) {
					layer.msg('操作成功!', {
						icon : 1,
						time : 800
					});
					setTimeout(function() {
						parent.querry();
						parent.layer.close(index);
					}, 1000);
				} else {
					layer.msg('操作失败!', {
						icon : 2,
						time : 800
					});
					lock = false;
				}
			}
		});
	}

	function insert() {
		if (!lock) {
			insertData();
		}
	}
</script>
</html>
